/**
* 日期转换工具方法
*/


//日期转换 年月日
export function formatDate(time, fmt) {
	fmt = fmt || "yyyy-MM-dd"
	return new Date(time).format(fmt)
}

//日期转换 年月日
export function formatDateTime(time, fmt) {
	fmt = fmt || "yyyy-MM-dd hh:mm:ss"
	return new Date(time).format(fmt)
}


//计算2个日期的天数查 day1<day2 返回负数 
export function dateDiff(day1, day2) {
	if (!day1 || !day2) {
		return null;
	}
	if (!(day1 instanceof Date)) {
		day1 = new Date(day1);
	}
	if (!(day2 instanceof Date)) {
		day2 = new Date(day2);
	}

	return (day1 - day2) / (1 * 24 * 60 * 60 * 1000);
}

//字符串转换日期 入参要求是yyyyMMddhhmmss
export function timeFormat(value) {
	let stack = [":",":"," ","-","-",""]
	let fmtTime = ''
	for(let i=0; i<value.length; i++){
		fmtTime += value[i]
		if(i%2==1 && stack.length>0){
			fmtTime += stack.pop()
		}
	}
	return fmtTime;
}
